package com.itheima.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.itheima.dao.ReportDao;
import com.itheima.service.MemberService;
import com.itheima.service.OrderService;
import com.itheima.service.ReportService;
import com.itheima.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author hql
 * @date 2019-12-13 11:26
 */

@Service(interfaceClass = ReportService.class)
@Transactional
public class ReportServiceImpl implements ReportService  {
    @Autowired
    private MemberService memberService;
    @Autowired
    private OrderService orderService;


/*    reportDate:null,  当前时间
    todayNewMember :0,  今天注册会员数
    totalMember :0,        总会员数
    thisWeekNewMember :0,  这周的注册会员数
    thisMonthNewMember :0, 这个月的注册会员数
    todayOrderNumber :0, 今天预约的人数
    todayVisitsNumber :0,   今天就诊的人数
    thisWeekOrderNumber :0, 这周预约的人数
    thisWeekVisitsNumber :0, 这周到诊的人数
    thisMonthOrderNumber :0,  这个月预约的人数
    thisMonthVisitsNumber :0,   这月到诊的人数
    hotSetmeal :[
    {name:'阳光爸妈升级肿瘤12项筛查（男女单人）体检套餐',setmeal_count:200,proportion:0.222},
    {name:'阳光爸妈升级肿瘤12项筛查体检套餐',setmeal_count:200,proportion:0.222}  ]*/

    /**
     * 返回当前所需的所有对象
     * @return
     */
    @Override
    public Map<String, Object> getBusinessReportData() throws Exception {
        Map<String, Object> map = new HashMap<>();
        //封装当前时间
        String reportDate = DateUtils.parseDate2String(new Date());
        map.put("reportDate",reportDate);
        //封装今天注册会员数
        Integer todayNewMember = memberService.findByTodayNewMember(reportDate);
        map.put("todayNewMember",todayNewMember);
        //封装总总员数
        Integer totalMember = memberService.findAllMember();
        map.put("totalMember",totalMember);
        //封装这周的总会员数
        //拿到这周的第一天
        String firstDayOfWeek = DateUtils.parseDate2String(DateUtils.getFirstDayOfWeek(new Date()));
        Integer thisWeekNewMember = memberService.findThisWeekNewMember(firstDayOfWeek);
        map.put("thisWeekNewMember",thisWeekNewMember);
        //拿到这个月的第一天，封装这个月的总会员数
        String firstDayOfMonth = DateUtils.parseDate2String(DateUtils.getFirstDay4ThisMonth());
        Integer thisMonthNewMember = memberService.findThisWeekNewMember(firstDayOfMonth);
        map.put("thisMonthNewMember",thisMonthNewMember);
        //拿到今天预约的人数
        Integer todayOrderNumber=orderService.getTodayOrderNumber(reportDate);
        map.put("todayOrderNumber",todayOrderNumber);
        //拿到今天就诊的人数
        Integer todayVisitsNumber = orderService.getTodayVisitsNumber(reportDate);
        map.put("todayVisitsNumber",todayVisitsNumber);
        //拿到这周预约的人数
        Integer thisWeekOrderNumber = orderService.getThisWeekOrderNumber(firstDayOfWeek);
        map.put("thisWeekOrderNumber",thisWeekOrderNumber);
        //拿到这周到诊的人数
        Integer thisWeekVisitsNumber=orderService.getThisWeekVisitsNumber(firstDayOfWeek);
        map.put("thisWeekVisitsNumber",thisWeekVisitsNumber);
        //拿到这个月预约的人数
        Integer thisMonthOrderNumber=orderService.getThisWeekOrderNumber(firstDayOfMonth);
        map.put("thisMonthOrderNumber",thisMonthOrderNumber);
        //拿到这个月到诊的人数
        Integer thisMonthVisitsNumber = orderService.getThisWeekVisitsNumber(firstDayOfMonth);
        map.put("thisMonthVisitsNumber",thisMonthVisitsNumber);
        //拿到火热套餐的所有信息
        List<Map<String,Object>> hotSetmealList = orderService.findHotSetmealList();
        map.put("hotSetmeal",hotSetmealList);
        return map;
    }

}
